package com.bkhech.controller;


import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import com.bkhech.RequestConstant;
import com.bkhech.grace.result.GraceJSONResult;
import com.bkhech.pojo.bo.NewFriendRequestBO;
import com.bkhech.service.FriendRequestService;
import com.bkhech.utils.PagedGridResult;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/friendRequest")
public class FriendRequestController {


    @Resource
    private FriendRequestService friendRequestService;

    @PostMapping("/add")
    public GraceJSONResult add(@RequestBody @Valid NewFriendRequestBO newFriendRequestBO){
        friendRequestService.addNewRequest(newFriendRequestBO);
        return GraceJSONResult.ok();
    }

    @PostMapping("/queryNew")
    public GraceJSONResult queryNew(HttpServletRequest request,
                                    @RequestParam(defaultValue = "1", name = "page") Integer page,
                                    @RequestParam(defaultValue = "10", name = "pageSize") Integer pageSize){
        String userId = request.getHeader(RequestConstant.HEADER_USER_ID);
        PagedGridResult pageResult = friendRequestService.queryNewFriendList(userId, page, pageSize);
        return GraceJSONResult.ok(pageResult);
    }

    @PostMapping("/pass")
    public GraceJSONResult pass(@RequestParam String friendRequestId, @RequestParam String friendRemark){
        friendRequestService.passNewFriend(friendRequestId, friendRemark);
        return GraceJSONResult.ok();
    }
}
